package com.yc.http;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;

public class Config {

    // Map 键值对存储
    // 可以直接读取 .properties 结构的文件, 也可以保存集合的内容到文件
    Properties properties = new Properties();

    public Config() throws IOException {
        this.load();
    }

    public void load() throws IOException {
        // 类加载器
        ClassLoader classLoader = Config.class.getClassLoader();
        // 读取配置
        InputStream in = classLoader.getResourceAsStream("server.properties");
        try(// 字节流转字符流
            InputStreamReader isr = new InputStreamReader(in,"UTF-8");){
            properties.load(isr);
        }
        System.out.println("properties = " + properties);
    }

    public String getConfig(String name){
        return properties.getProperty(name);
    }


}
